#!/bin/bash
ASSIGNMENT_NUM=lab3
SIMTRAXROOT=../
SAMPLE_DIR=${SIMTRAXROOT}samples/
SCENE_DIR=${SAMPLE_DIR}scenes

ASSEMBLY=${SAMPLE_DIR}src/atomtrace/rt-llvm.s

NUM_PROCS=32
NUM_ICACHE_BANKS=16
NUM_ICACHES=2
THREADS_PER_PROC=1
CACHE_CONFIG_FILE_NUM=1
# hardware configuration file
CONFIGS=${SAMPLE_DIR}configs/l1conf${CACHE_CONFIG_FILE_NUM}.config


L1_ON=1
DCACHE_AREA_ON=1

L1_CONFIG=""
DCACHE_CONFIG=""
# simulation report file
OUTPUT_FILE=../${ASSIGNMENT_NUM}_l1_${L1_ON}_dcachearea_${DCACHE_CONFIG}_useL1Conf${CACHE_CONFIG_FILE_NUM}_report.txt

RENDER_CORNELL=
RENDER_CONFERENCE=

PROFILE="--profile"

CORNELL_OBJ=$SCENE_DIR/cornell/CornellBox.obj
CORNELL_VIEW=$SCENE_DIR/cornell/cornell.view
CORNELL_LIGHT=$SCENE_DIR/cornell/cornell.light

CONFER_OBJ=$SCENE_DIR/conference/conference.obj
CONFER_VIEW=$SCENE_DIR/conference/conference.view
CONFER_LIGHT=$SCENE_DIR/conference/conference.light


updateConfig() {
    
    OUTPUT_FILE=../${ASSIGNMENT_NUM}_l1_${L1_ON}_useL1Conf${CACHE_CONFIG_FILE_NUM}${PROFILE}_report.txt
    #echo "output file name config finish"

    CONFIGS=${SAMPLE_DIR}configs/l1conf${CACHE_CONFIG_FILE_NUM}.config

    CORNELL_SCENE="--model $CORNELL_OBJ --view-file $CORNELL_VIEW --light-file $CORNELL_LIGHT"

    CONFERENCE_SCENE="--model $CONFER_OBJ --view-file $CONFER_VIEW --light-file $CONFER_LIGHT"

    SIMTRAXCONF="--disable-usimm --load-assembly $ASSEMBLY --num-thread-procs $NUM_PROCS --num-icache-banks $NUM_ICACHE_BANKS --num-icaches $NUM_ICACHES $DCACHE_CONFIG $L1_CONFIG --l2-off --config-file $CONFIGS $PROFILE"


    RENDER_CORNELL="./simtrax $CORNELL_SCENE $SIMTRAXCONF"

    RENDER_CONFERENCE="./simtrax $CONFERENCE_SCENE $SIMTRAXCONF"

}

#$RENDER_CORNELL
SingleRun () {
    updateConfig
    echo "Render configuration:"
    echo $RENDER_CONFERENCE
    echo "Output file:"
    echo $OUTPUT_FILE
    ${RENDER_CONFERENCE} > $OUTPUT_FILE
    echo "Done."
}

L1ConfRun () {
    x=5
    while [ $x -le 8 ]; do
        CACHE_CONFIG_FILE_NUM=$x
        echo "config file l1conf${CACHE_CONFIG_FILE_NUM}.config running"
        SingleRun
        echo "Progress is $x/16"
        #echo $x
        (( x++ ))
    done
}

RunL1Conf10 ()
{
    CACHE_CONFIG_FILE_NUM=10
    echo "config file l1conf${CACHE_CONFIG_FILE_NUM}.config running"
    SingleRun
}

RunL1Conf10
#L1ConfRun
#gthumb ./out.png &
